﻿function updateList(tableId, list, getIdFromDataItem, getUrlForNewItem) {
    var hadNewData = false;
    for (var i in list) {
        var dataItem = list[i];

        var id = getIdFromDataItem(dataItem);
        var row = $('#' + id);

        if (row.length == 0) {
            hadNewData = true;
            row = $('.datarowTemplate').clone();
            row.attr('id', id).removeClass('datarowTemplate');
            var href = row.find('a').attr('href');
            row.find('a').attr('href', getUrlForNewItem(href, dataItem));
            $('#' + tableId).append(row);
        }

        for (var element in dataItem) {
            var spanWithContents = row.find(' .' + element);
            if (spanWithContents.length > 0 && spanWithContents.text() != dataItem[element]) {
                spanWithContents.text(dataItem[element]);
                hadNewData = true;
            }
        }
    }

    return hadNewData;
}